/**
 * fulihui.com Inc.
 * Copyright (c) 2015-2016 All Rights Reserved.
 */
package com.fulihui.information.biz.conv;

import com.fulihui.information.dal.dataobj.InfoComments;
import com.fulihui.information.dto.CommentsDTO;
import org.near.toolkit.collection.ExtCollectionUtils;
import org.near.toolkit.common.DateUtils;
import org.springframework.beans.BeanUtils;

import java.text.ParseException;
import java.util.List;

/**
 * @author yunfeng.li
 * @version $Id: v 0.1 2017年01月10日 15:43 yunfeng.li Exp $
 */
public class CommentsConv {

    private static final String[] ignore = { "discussTime","gmtCreate", "gmtModified","subComments" };

    /**
     * do to dto
     *
     * @param mo_
     * @return
     */
    public static InfoComments convert2DO(CommentsDTO mo_) {
        if (mo_ == null) {
            return null;
        }

        InfoComments do_ = new InfoComments();
        BeanUtils.copyProperties(mo_, do_, ignore);

        try {
            do_.setDiscussTime(DateUtils.parse(mo_.getDiscussTime(), DateUtils.newFormat));
            do_.setGmtCreate(DateUtils.parse(mo_.getGmtCreate(), DateUtils.newFormat));
            do_.setGmtModified(DateUtils.parse(mo_.getGmtModified(), DateUtils.newFormat));
        } catch (ParseException e) {

        }

        return do_;
    }

    /**
     * dto to do
     *
     * @param do_
     * @return
     */
    public static CommentsDTO convert2DTO(InfoComments do_) {
        if (do_ == null) {
            return null;
        }

        CommentsDTO mo_ = new CommentsDTO();
        BeanUtils.copyProperties(do_, mo_, ignore);
        mo_.setDiscussTime(DateUtils.format(do_.getDiscussTime(),DateUtils.newFormat));
        mo_.setGmtCreate(DateUtils.format(do_.getGmtCreate(), DateUtils.newFormat));
        mo_.setGmtModified(DateUtils.format(do_.getGmtModified(), DateUtils.newFormat));

        return mo_;
    }

    /**
     * 批量
     *
     * @param list
     * @return
     */
    public static List<CommentsDTO> convert2List(List<InfoComments> list) {
        return (List<CommentsDTO>) ExtCollectionUtils.collect(list,
                CommentsConv::convert2DTO);
    }
}
